trigger ProcessActivityOrder on Order_Item__c (after insert) {
    
    set<string> resourceIdList=new set<string>();//保存资源ID
    List<Order_Item__c> oItemList=new List<Order_Item__c>();
    for(Order_Item__c oItem:trigger.new)
    {
        if(oItem.Order_Type__c=='活动订单')
        {
            if(oItem.Resource_Allocation_Detail__c!=NULL)
                resourceIdList.add(oItem.Resource_Allocation_Detail__c);
            oItemList.add(oItem);
        }
    }
    map<id,Resource_Allocation_Detail__c> radList=new map<id,Resource_Allocation_Detail__c>([select id,
                                                                                                                                                    Resource_Quantity_Number__c,
                                                                                                                                                    HasUsedResourceNumber__c 
                                                                                                                                                    from Resource_Allocation_Detail__c 
                                                                                                                                                    where id in:resourceIdList]);
    for(Order_Item__c oItem:oItemList)
    {
        if(radList.containsKey(oItem.Resource_Allocation_Detail__c))
        {
             if(oItem.OrderNumber__c>0)
             {
                Resource_Allocation_Detail__c rad=radList.get(oItem.Resource_Allocation_Detail__c);
                if(rad.HasUsedResourceNumber__c==NULL)
                    rad.HasUsedResourceNumber__c=0;
                
                rad.HasUsedResourceNumber__c+=oItem.OrderNumber__c;//累加已使用量
                radList.put(oItem.Resource_Allocation_Detail__c,rad);
            }
        }
    }
    update radList.values();
}